<?php
namespace app\work\controller;
use app\work\logic\CloudLogic;

/**
 * 工作云盘api控制器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/10/30
 * Time: 15:31
 */
class Cloud extends Base {

    public function __construct(){
        parent::__construct();
        $this->c_logic = new CloudLogic();
    }

    /**
     * 获取云盘
     * @return \think\response\Json
     */
    public function ajax_get_cloud(){
        $params = input();
        $r = $this->check_user_token($params);
        if($r['code'] != 1){
            return json($r);
        }

        //检查用户规则
        $r = $this->c_logic->check_user_rule();
        if($r['code'] != 1){
            return json($r);
        }
        $u_detail = $r['data']['detail'];
        
        $maps = $this->c_logic->get_search_cloud_maps($params['parentid'],$params['keywords']);

        $list = model('work_record_cloud')->get_list($maps,'id,type,name,size,url,parentid,is_password,password,c_time','type asc,id desc');

        $wrc_maps = [];
        $wrc_maps[] = ['id','=',$params['parentid']];
        $wrc_detail = model('work_record_cloud')->get_detail($wrc_maps,'id,parentid,name');

        $data['list'] = $list;
        $data['parentid'] = $params['parentid'];
        $data['parent_zw'] = !empty($wrc_detail) ? $wrc_detail['name'] : '';
        $data['last_parentid'] = !empty($wrc_detail) ? $wrc_detail['parentid'] : 0;
        return json($this->c_logic->get_response(1,'OK',$data));
    }
}
